package com.atguigu.edusocket.controller;

import com.atguigu.commonutils.R;
import com.atguigu.edusocket.config.WebSocketServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/edusocket/demo")
public class SocketDemoController {

    @GetMapping("/index")
    public R index(){
        return R.ok();
    }
//
//    @GetMapping("page")
//    public ModelAndView page(){
//        return new ModelAndView("websocket");
//    }

    @RequestMapping("/push/{toUserId}")
    public R pushToWeb(String message, @PathVariable String toUserId) throws IOException {
        WebSocketServer.sendInfo(message,toUserId);
        return R.ok();
    }
}
